package com.example.saiweisi.service.impl.sysTemAdminService;

import com.example.saiweisi.controller.request.ChefAdminRequest;
import com.example.saiweisi.mapper.systemAdminMapper.ChefAdminMapper;
import com.example.saiweisi.model.ChefAdmin;
import com.example.saiweisi.service.interf.IChefAdminService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChefAdminService implements IChefAdminService {
    @Autowired
    ChefAdminMapper chefAdminMapper;
    @Override
    public PageInfo<ChefAdmin> page(ChefAdminRequest chefAdminRequest) {
        PageHelper.startPage(chefAdminRequest.getPageNum(), chefAdminRequest.getPageSize());
        List<ChefAdmin> userList = chefAdminMapper.chefadminlistByCondition(chefAdminRequest);
        return new PageInfo<>(userList);
    }

    @Override
    public void addchefadmin(ChefAdmin chefAdmin) {
        //遍历数据库，将最大的 num加一 赋值给新用户，来达到生成唯一标识符的目的
        int s=1;
        List<ChefAdmin> list=chefAdminMapper.getall();
        for (ChefAdmin a:list
        ) {
            if(Integer.parseInt(a.getChefAdminNum().substring(1))>s){
                s=Integer.parseInt(a.getChefAdminNum().substring(1));
            }
        }
//        String b=IdUtil.fastSimpleUUID();
//        Integer a=Integer.parseInt(b);
        chefAdmin.setChefAdminNum("300"+Integer.toString(s+1));
        chefAdminMapper.addchefadmin(chefAdmin);
    }

    @Override
    public void deletechefadmin(Integer chefAdminId) {
        chefAdminMapper.deletechefadmin(chefAdminId);
    }

    @Override
    public ChefAdmin getById(Integer chefAdminId) {
        return chefAdminMapper.getById(chefAdminId);
    }

    @Override
    public void updatechefadmin(ChefAdmin chefAdmin) {
        chefAdminMapper.updatechefadmin(chefAdmin);
    }

    @Override
    public void deleteschefadmin(List<Integer> chefAdminIds) {
        for (Integer a:chefAdminIds
             ) {
            chefAdminMapper.deletechefadmin(a);
        }
    }

    @Override
    public void resetPassword(Integer chefAdminId) {
        chefAdminMapper.resetPassword(chefAdminId);
    }
}
